/**********************************************************************
 * Project : WoWGuildRoster (http://www.codeplex.com/WowGuildRoster/)
 * Module  : DotNetWarcraft.WoWGuildRoster.Business.Exceptions
 **********************************************************************
 * 
 * 
 * 
 **********************************************************************
 * License : All code is subject to licensing terms per the Microsoft
 *   Permissive License (Ms-PL) v1.1. For full license information,
 *   refer to the packaged license.txt file.
 **********************************************************************
 * Revision History:
 * -----------------
 * 2007-07-29 -- Cliff Simpkins: Initial Version
 **********************************************************************
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using DotNetWarcraft.Common;

namespace DotNetWarcraft.WoWGuildRoster.Business.Exceptions {

  //internal class ExceptionLogger {
  //  #region Public Methods
  //  public static void ProcessGeneralException(Exception e, String additionalInfo) {
  //    GuildRosterError _error = new GuildRosterError(e, additionalInfo);
  //    ProcessException(_error);
  //  }
  //  public static void ProcessGeneralException(Exception e) {
  //    ProcessGeneralException(e, "");
  //  }


  //  public static void ProcessLoadException(Exception e, int loadID) {
  //    ProcessLoadException(e, loadID, "");
  //  }
  //  public static void ProcessLoadException(Exception e, int loadID, String additionalInfo) {
  //    GuildRosterError _error = new GuildRosterError(e, additionalInfo);
  //    _error.LoadID = loadID;

  //    ProcessException(_error);
  //  }

  //  public static void ProcessRosterException(Exception e, int rosterID) {
  //    ProcessRosterException(e, -1, rosterID, "");
  //  }
  //  public static void ProcessRosterException(Exception e, int rosterID, String additionalInfo) {
  //    ProcessRosterException(e, -1, rosterID, additionalInfo);
  //  }
  //  public static void ProcessRosterException(Exception e, int loadID, int rosterID) {
  //    ProcessRosterException(e, loadID, rosterID, "");
  //  }
  //  public static void ProcessRosterException(Exception e, int loadID, int rosterID, String additionalInfo) {
  //    GuildRosterError _error = new GuildRosterError(e, additionalInfo);
  //    _error.LoadID = loadID;
  //    _error.RosterID = rosterID;

  //    ProcessException(_error);
  //  }

  //  public static void ProcessCharException(Exception e, int loadID, int rosterID, int charID) {
  //    ProcessCharException(e, loadID, rosterID, charID, "");
  //  }
  //  public static void ProcessCharException(Exception e, int loadID, int rosterID, int charID, String additionalInfo) {
  //    GuildRosterError _error = new GuildRosterError(e, additionalInfo);
  //    _error.LoadID = loadID;
  //    _error.RosterID = rosterID;
  //    _error.CharID = charID;

  //    ProcessException(_error);
  //  }

  //  public static void ProcessCharStatException(Exception e, int loadID, int rosterID, int charID, int charStatID) {
  //    ProcessCharStatException(e, loadID, rosterID, charID, charStatID, "");
  //  }
  //  public static void ProcessCharStatException(Exception e, int loadID, int rosterID, int charID, int charStatID, String additionalInfo) {
  //    GuildRosterError _error = new GuildRosterError(e, additionalInfo);
  //    _error.LoadID = loadID;
  //    _error.RosterID = rosterID;
  //    _error.CharID = charID;
  //    _error.CharStatID = charStatID;

  //    ProcessException(_error);
  //  }


  //  #endregion
  //}


  public abstract class WoWGuildRosterException : System.ApplicationException {
    #region Protected Members
    protected int _errorID;
    protected int _loadID;
    protected int _rosterID;
    protected int _charID;
    protected int _charStatID;

    protected DateTime _errorTime;

    protected Exception _exc;

    protected String _addtInfo;
    protected String _callingMethod;
    #endregion
    #region Public Properties
    public int ErrorID {
      get {
        return _errorID;
      }
      set {
        _errorID = value;
      }
    }
    public int LoadID {
      get {
        return _loadID;
      }
      set {
        _loadID = value;
      }
    }
    public int RosterID {
      get {
        return _rosterID;
      }
      set {
        _rosterID = value;
      }
    }
    public int CharID {
      get {
        return _charID;
      }
      set {
        _charID = value;
      }
    }
    public int CharStatID {
      get {
        return _charStatID;
      }
      set {
        _charStatID = value;
      }
    }
    public String AdditionalInfo {
      get {
        return _addtInfo;
      }
      set {
        _addtInfo = value;
      }
    }

    public DateTime ErrorTime {
      get {
        return _errorTime;
      }
      set {
        _errorTime = value;
      }
    }

    public Exception Exception {
      get {
        return _exc;
      }
      set {
        _exc = value;
      }
    }
    #endregion
    #region Constructors
    public WoWGuildRosterException() {
      this.ErrorID = -1;
      this.LoadID = -1;
      this.RosterID = -1;
      this.CharID = -1;
      this.CharStatID = -1;
      this.AdditionalInfo = "";

      this.ErrorTime = DateTime.UtcNow;
      this.Exception = null;
    }
    public WoWGuildRosterException(Exception e) : this() {
      this.Exception = e;
    }

    public WoWGuildRosterException(Exception e, String additionalInfo)
      : this() {
      this.AdditionalInfo = additionalInfo;
      this.Exception = e;
    }

    public WoWGuildRosterException(DataRow errorSrc)
      : base() {
      this.ErrorID = SqlDataUtils.RetrieveDbInt(errorSrc["error_id"]);
      this.LoadID = SqlDataUtils.RetrieveDbInt(errorSrc["load_id"]);
      this.CharID = SqlDataUtils.RetrieveDbInt(errorSrc["char_id"]);
      this.CharStatID = SqlDataUtils.RetrieveDbInt(errorSrc["charstat_id"]);
      this.ErrorTime = SqlDataUtils.RetrieveDbDate(errorSrc["error_datetime"]);
      this.AdditionalInfo = SqlDataUtils.RetrieveDbString(errorSrc["error_wgr_info"]);
      }


    #endregion

    /*
    public void WriteExceptionToDB() {
      try {
        DotNetWarcraft.WoWGuildRoster.Data.DataProvider.Instance().AddError(this);
      } catch (SqlException _e) {
        String _type = _e.GetType().ToString();
        //throw this.Exception;
      } catch (Exception _e) {
        String _type = _e.GetType().ToString();
        //throw _e;
      }    
    }
     */
  }

  public class WGRGeneralError : WoWGuildRosterException {
    #region Constructors
    public WGRGeneralError() : base() {
    }
    public WGRGeneralError(Exception e) : base(e){
    }
    public WGRGeneralError(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }

    public WGRGeneralError(DataRow errorSrc)
      : base(errorSrc) {
      }


    #endregion
  }
  public class NoConnectStringValueSpecified : WoWGuildRosterException {
    #region Constructors
    public NoConnectStringValueSpecified()
      : base() {
    }
    public NoConnectStringValueSpecified(Exception e)
      : base(e) {
    }
    public NoConnectStringValueSpecified(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
    public NoConnectStringValueSpecified(String callingMethod)
      : base() {
      _callingMethod = callingMethod;
    }

    #endregion

    public override string Message {
      get {
        if (_callingMethod == null || _callingMethod.Trim() == "") {
          return "The ConnectionString is not set.";
        } else {
          return _callingMethod + " - The ConnectionString is not set.";
        }
      }
    }
  }
  public class GuildLoadError : WoWGuildRosterException {
    #region Constructors
    public GuildLoadError()
      : base() {
    }
    public GuildLoadError(Exception e)
      : base(e) {
    }
    public GuildLoadError(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
    public GuildLoadError(Exception e, int loadID, String additionalInfo)
      : base(e, additionalInfo) {
      this.LoadID = loadID;
    }
    #endregion
  }
  public class GuildRosterError : WoWGuildRosterException {
    #region Constructors
    public GuildRosterError()
      : base() {
    }
    public GuildRosterError(Exception e)
      : base(e) {
    }
    public GuildRosterError(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
    public GuildRosterError(Exception e, int loadID, int rosterID, String additionalInfo)
      : base(e, additionalInfo) {
      this.LoadID = loadID;
      this.RosterID = rosterID;
    }
    #endregion
  }
  public class GuildCharEntryError : WoWGuildRosterException {
    #region Constructors
    public GuildCharEntryError()
      : base() {
    }
    public GuildCharEntryError(Exception e)
      : base(e) {
    }
    public GuildCharEntryError(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
    public GuildCharEntryError(Exception e, int loadID, int rosterID, int charEntryID, String additionalInfo)
      : base(e, additionalInfo) {
      this.LoadID = loadID;
      this.RosterID = rosterID;
      this.CharID = charEntryID;
    }

    #endregion
  }
  public class GuildCharEntryStatError : WoWGuildRosterException {
    #region Constructors
    public GuildCharEntryStatError()
      : base() {
    }
    public GuildCharEntryStatError(Exception e)
      : base(e) {
    }
    public GuildCharEntryStatError(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
    public GuildCharEntryStatError(Exception e, int loadID, int rosterID, int charEntryID, int charEntryStatID, String additionalInfo)
      : base(e, additionalInfo) {
      this.LoadID = loadID;
      this.RosterID = rosterID;
      this.CharID = charEntryID;
      this.CharStatID = charEntryStatID;
    }

    #endregion
  }

  //#region "Invalid LUA File Exceptions"
  //public abstract class InvalidLuaFile : WoWGuildRosterException {
  //  protected const String MessagePrefix = "Invalid LUA File Uploaded: ";
  //}

  //public class InvalidLuaFile_InvalidVersion : InvalidLuaFile {
  //  String _luaVersion = "", _versionMin = "", _versionMax = "";

  //  public InvalidLuaFile_InvalidVersion(String LuaVersion, String VersionMin, String VersionMax)
  //    : base() {
  //    _luaVersion = LuaVersion;
  //    _versionMin = VersionMin;
  //    _versionMax = VersionMax;
  //  }
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded version (v" + _luaVersion + ") must be between v" + _versionMin + " and v" + _versionMax + ".";
  //    }
  //  }

  //}
  //public class InvalidLuaFile_NoServerData : InvalidLuaFile {
  //  String _server = "";

  //  public InvalidLuaFile_NoServerData(String ServerName)
  //    : base() {
  //    _server = ServerName;
  //  }
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded LUA file did not contain the requested server (" + _server + ").";
  //    }
  //  }
  //}

  //public class InvalidLuaFile_NoGuildData : InvalidLuaFile {
  //  String _guild = "";

  //  public InvalidLuaFile_NoGuildData(String GuildName)
  //    : base() {
  //    _guild = GuildName;
  //  }
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded LUA file did not contain the requested guild (" + _guild + ").";
  //    }
  //  }
  //}

  //public class InvalidLuaFile_NoServerGuildData : InvalidLuaFile {
  //  String _server = "", _guild = "";

  //  public InvalidLuaFile_NoServerGuildData(String ServerName, String GuildName)
  //    : base() {
  //    _server = ServerName;
  //    _guild = GuildName;
  //  }
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded LUA file did not contain the requested server/guild combination (" + _server + "/ " + _guild + ").";
  //    }
  //  }
  //}


  //public class InvalidLuaFile_Malformed_NoCaptureBlock : InvalidLuaFile {
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded LUA file did not contain a CAPTURE block.";
  //    }
  //  }
  //}
  //public class InvalidLuaFile_Malformed_NoGbDataBlock : InvalidLuaFile {
  //  public override string Message {
  //    get {
  //      return MessagePrefix + "The uploaded LUA file did not contain a GB_DATA block.";
  //    }
  //  }
  //}


  //#endregion

  #region "Roster Exceptions"
  public abstract class RosterExceptions : WoWGuildRosterException {
    protected const String MessagePrefix = "Roster Error: ";

    public RosterExceptions()
      : base() {
    }
    public RosterExceptions(Exception e, String additionalInfo)
      : base(e, additionalInfo) {
    }
}

  public class RosterRowInvalid : RosterExceptions {
    public RosterRowInvalid(Exception e, int rosterID, String additionalInfo)
      : base(e, additionalInfo) {
      this.RosterID = rosterID;
    }
    public RosterRowInvalid(int rosterID) {
      this.RosterID = rosterID;
      }
    public RosterRowInvalid(int rosterID, String additionalInfo)
      : this(rosterID) {
      }

    public override string Message {
      get {
        return MessagePrefix + "Row passed to Runtime was not found in database (" + this.RosterID + ")";
        }
      }
    }

  #endregion
}
